﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// 玩家输入控制器
/// </summary>
public class InputManager : SingletonProvider<InputManager>
{
    /// <summary>
    /// 输入开关
    /// </summary>
    public bool isOpen { get; set; } = false;
    public InputManager()
    {
        MonoManager.GetInstance().AddUpdateListener(Update);
    }
    /// <summary>
    /// 每帧检测
    /// </summary>
    private void Update()
    {
        if (!isOpen)
        {
            return;
        }
        CheckKeyCode();
    }
    /// <summary>
    /// 检测按键
    /// </summary>
    private void CheckKeyCode()
    {
        CheckKeyDown();
        CheckKeyUp();
    }
    /// <summary>
    /// 按下按键
    /// </summary>
    private void CheckKeyDown()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            EventCenter.GetInstance().EventTrigger("Start Accumulating");
        }
        if (Input.GetKeyDown(KeyCode.R))
        {
            GameManager.GetInstance().ReStart();
        }
    }
    /// <summary>
    /// 松开按键
    /// </summary>
    private void CheckKeyUp()
    {
        if (Input.GetKeyUp(KeyCode.Space))
        {
            EventCenter.GetInstance().EventTrigger("End Accumulating");
        }
    }
}
